package com.lysj.admin.master.bussiness.company.recharge.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lysj.admin.master.bussiness.company.company.dto.CompanyBaseDto;
import com.lysj.admin.master.bussiness.company.recharge.domain.CostRecord;
import com.lysj.admin.master.bussiness.company.recharge.mapper.CostRecordMapper;
import com.lysj.admin.master.bussiness.company.recharge.service.CostRecordService;
import com.lysj.admin.master.common.CommonConstant;
import com.lysj.admin.master.common.annotation.MyList;
import com.lysj.admin.master.common.enumeration.EnumUtils;
import com.lysj.admin.master.common.spring.mpbase.MyController;
import com.lysj.admin.master.common.spring.mpbase.MyService;
import com.lysj.admin.master.common.spring.pagination.PageRequestDTO;
import com.lysj.admin.master.common.web.Resp;
import com.lysj.admin.master.common.web.RespUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author Created by drj on 2020-01-07 20:19
 * @description
 */
@Slf4j
@RestController
@RequestMapping("/company/cost_record")
public class CostRecordController extends MyController<CostRecordMapper, CostRecord, PageRequestDTO> {

    @Resource
    private CostRecordService costRecordService;

    @Override
    public MyService<CostRecordMapper, CostRecord> getService() {
        return costRecordService;
    }

    @MyList
    public Resp list(CompanyBaseDto condition) {
        //获取当前登录代理商
        String companyId = getJwtProperty(CommonConstant.COMPANY_ID_NAME);
        condition.setCompanyId(companyId);
        Page<CostRecord> costRecordPage = getService().pageList(condition);
        for (CostRecord costRecord : costRecordPage.getRecords()) {
         costRecord.setOperationTxt(EnumUtils.findStatusByCode(costRecord.getOperation(),CostRecord.Operation.class));
        costRecord.setOperationTypeTxt(EnumUtils.findStatusByCode(costRecord.getOperationType(),CostRecord.OperationType.class));
        }
        return RespUtil.success(costRecordPage);
    }
}
